package com.itheima.controller;

import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.entity.TableData;
import com.itheima.pojo.Goods;
import com.itheima.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean) {
        log.debug("GoodsController findByPage param:" + queryPageBean);
        TableData tableData = goodsService.findByPage(queryPageBean);
        log.debug("GoodsController findByPage result:" + tableData);
        return new Result(true,"分页查询数据成功",tableData);
    }

    @RequestMapping("add")
    public Result add(@RequestBody Goods goods) {
        log.debug("add param:" + goods);
        goodsService.add(goods);
        return new Result(true,"添加成功");
    }

    @RequestMapping("edit")
    public Result edit(@RequestBody Goods goods) {
        log.debug("edit param:" + goods);
        goodsService.edit(goods);
        return new Result(true,"更新成功");
    }

    @RequestMapping("delById")
    public Result delById(Integer id) {
        log.debug("delById param:" + id);
        goodsService.delById(id);
        return new Result(true,"删除成功");
    }
}
